package com.gibs.peixunapi.dao;

import java.util.List;

import com.gibs.peixunapi.model.ExerciseRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.StudyProgress;

@Repository
public interface StudyProgressDao extends JpaRepository<StudyProgress, Integer>, JpaSpecificationExecutor<StudyProgress> {

    @Query("from StudyProgress where studentId = ?1")
    List<StudyProgress> find(String name);

    @Query("from StudyProgress where studentId like ?1")
    List<StudyProgress> findLike(String name);

    @Query(value = "select * from StudyProgress limit ?, ?", nativeQuery = true)
    List<StudyProgress> findPage(Integer offset, Integer size);

    @Query(value = "select * from StudyProgress where studentId = ? limit ?, ?", nativeQuery = true)
    List<StudyProgress> findPage(String name, Integer offset, Integer size);

    @Query(value = "select * from StudyProgress where studentId like ? limit ?, ?", nativeQuery = true)
    List<StudyProgress> findPageLike(String name, Integer offset, Integer size);

    @Query(value = "select count(*) from StudyProgress where studentId = ?", nativeQuery = true)
    Long count(String name);

    @Query(value = "select count(*) from StudyProgress where studentId like ?", nativeQuery = true)
    Long countLike(String name);

    @Query("from StudyProgress order by id asc")
    List<StudyProgress> findAllAsc();

    @Query("select timeRecord from StudyProgress where videoClass.id = ?1 and student.id = ?2")
    Integer findTimeRecord(Integer videoClassId, Integer studentId);

	StudyProgress findByVideoClass_IdAndStudent_Id(Integer videoClassId, Integer studentId);
}

